﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Caching;
using System.Web;
using Shop.Model;
namespace Shop.Framework.Runtime {

    public class CMSRuntime {

        private static CMSRuntime Me = null;

        public ShopDetail Shop {
            get {
                return HttpRuntime.Cache[ShopKeeper] as ShopDetail;
            }        
        }
        
        public static CMSRuntime Instance {
            get {
                if (Me == null)
                    Me = new CMSRuntime();

                return Me;
            }
        }

        public bool IsLoggedIn() {            
            return Shop != null;
        }

        public void Logout() {
            HttpRuntime.Cache.Remove(ShopKeeper);
        }

        public const string ShopKeeper = "ShopKeeper";
        public void SetSuccessfulRegistration() {
            HttpContext.Current.Session["Succeeded"] = true;
        }

        public void Notified() {
            HttpContext.Current.Session["Succeeded"] = false;
        }

        public bool HaddRegistered {
            get {
                return HttpContext.Current.Session["Succeeded"] == null ?
                    false: 
                    Convert.ToBoolean(HttpContext.Current.Session["Succeeded"]);
            }
        }
                
    }
}
